<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI代理测试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input[type="text"], textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
        }
        button:hover {
            background-color: #0056b3;
        }
        .response {
            margin-top: 20px;
            padding: 15px;
            border-radius: 4px;
            white-space: pre-wrap;
        }
        .success {
            background-color: #d4edda;
            border: 1px solid #c3e6cb;
            color: #155724;
        }
        .error {
            background-color: #f8d7da;
            border: 1px solid #f5c6cb;
            color: #721c24;
        }
        .loading {
            background-color: #d1ecf1;
            border: 1px solid #bee5eb;
            color: #0c5460;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>AI代理测试页面</h1>
        
        <div class="form-group">
            <label for="command">输入命令:</label>
            <input type="text" id="command" placeholder="例如: 查看kubernetes, 打开微信, 查看天气" value="查看kubernetes">
        </div>
        
        <button onclick="sendCommand()">发送命令</button>
        <button onclick="testConnection()">测试连接</button>
        <button onclick="testAI()">测试AI</button>
        
        <div id="response" class="response" style="display: none;"></div>
    </div>

    <script>
        async function sendCommand() {
            const command = document.getElementById('command').value.trim();
            if (!command) {
                showResponse('请输入命令', 'error');
                return;
            }
            
            showResponse('正在处理命令...', 'loading');
            
            try {
                const response = await fetch('/api/agent/command', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        request: command
                    })
                });
                
                const data = await response.json();
                
                if (data.success) {
                    showResponse(`成功!\n\n结果: ${data.result}\n\n消息: ${data.message}`, 'success');
                } else {
                    showResponse(`错误: ${data.message}`, 'error');
                }
            } catch (error) {
                showResponse(`请求失败: ${error.message}`, 'error');
            }
        }
        
        async function testConnection() {
            showResponse('正在测试网络连接...', 'loading');
            
            try {
                const response = await fetch('/api/agent/test-connection');
                const data = await response.json();
                
                if (data.success) {
                    showResponse(`网络连接测试成功!\n\n响应码: ${data.responseCode}\n\n消息: ${data.message}`, 'success');
                } else {
                    showResponse(`网络连接测试失败: ${data.message}`, 'error');
                }
            } catch (error) {
                showResponse(`测试失败: ${error.message}`, 'error');
            }
        }
        
        async function testAI() {
            showResponse('正在测试AI连接...', 'loading');
            
            try {
                const response = await fetch('/api/agent/test-ai', {
                    method: 'POST'
                });
                const data = await response.json();
                
                if (data.success) {
                    showResponse(`AI连接测试成功!\n\n结果: ${data.result}\n\n消息: ${data.message}`, 'success');
                } else {
                    showResponse(`AI连接测试失败: ${data.message}`, 'error');
                }
            } catch (error) {
                showResponse(`测试失败: ${error.message}`, 'error');
            }
        }
        
        function showResponse(message, type) {
            const responseDiv = document.getElementById('response');
            responseDiv.textContent = message;
            responseDiv.className = `response ${type}`;
            responseDiv.style.display = 'block';
        }
        
        // 按回车键发送命令
        document.getElementById('command').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                sendCommand();
            }
        });
    </script>
</body>
</html> 